package com.bill99.util;

public class StringUtil {

    public static boolean isEmpty(String value) {
        boolean result = true;

        if (value != null && value.length() > 0) {
            result = false;
        }

        return result;
    }

    public static boolean isNotEmpty(String value) {
        return !StringUtil.isEmpty(value);
    }

    public static boolean isNull(String value) {
        return value == null;
    }

    public static boolean isNotNull(String value) {
        return !StringUtil.isNull(value);
    }

    public static String emptyAsNull(String value) {
        if (value == null) {
            return value;
        }

        if (value.trim().equals("")) {
            return null;
        } else {
            return value;
        }
    }

    public static boolean asBool(String value, boolean whenNull) {

        if (emptyAsNull(value) == null) {
            return whenNull;
        }

        return new Boolean(value);
    }

    public static String parseToString(String str) {
        if (str == null) {
            return null;
        }

        if ("".equals(str.trim())) {
            return null;
        }

        return str;
    }

}
